<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});

Auth::routes();

Route::get('/home', 'HomeController@index')->name('home');

Route::get('/redirect', function () {
    $query = http_build_query([
        'client_id' => '5',
        'redirect_uri' => 'http://my-blog.com/auth/callback',
        'response_type' => 'code',
        'scope' => '',
    ]);

    return redirect('http://my-blog.com/oauth/authorize?'.$query);
});

Route::get('/auth/password', function (\Illuminate\Http\Request $request){
    $http = new \GuzzleHttp\Client();

    $response = $http->post('http://my-blog.com/oauth/token', [
        'form_params' => [
            'grant_type' => 'password',
            'client_id' => '5',
            'client_secret' => 'vnuiuoldAfl9Wt2VYp9bfQh1qnQwsLXHarPJPsSQ',
            'username' => 'kobe.wang@etocrm.com',
            'password' => '123456',
            'scope' => '',
        ],
    ]);

    return json_decode((string)$response->getBody(), true);
});
